/*
  3D - C++ Class Library for 3-D Rigid Transformations
  Copyright (C) 1996, 1997  Gino van den Bergen

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Library General Public
  License as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Library General Public License for more details.

  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free
  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

  Please send remarks, questions and bug reports to gino@win.tue.nl,
  or write to:
                  Gino van den Bergen
		  Department of Mathematics and Computing Science
		  Eindhoven University of Technology
		  P.O. Box 513, 5600 MB Eindhoven, The Netherlands
*/

#ifndef _BASIC_H_
#define _BASIC_H_

// #include <bool.h>
#include <math.h>
#include <stdlib.h>

typedef double Scalar;

const Scalar EPSILON = 1e-10;
// const Scalar INFINITY = HUGE_VAL;
// double drand48(void) { return double(rand()) / RAND_MAX; };
const Scalar TWO_TIMES_PI = 2 * M_PI; 

inline Scalar abs(Scalar x) { return fabs(x); }
inline bool   eqz(Scalar x) { return abs(x) < EPSILON; }
inline int    sgn(Scalar x) { return x < 0 ? -1 : x == 0 ? 0 : 1; }
inline Scalar rnd() { return double(rand()) / RAND_MAX; }

inline void set_min(Scalar& x, Scalar y) { if (x > y) x = y; }
inline void set_max(Scalar& x, Scalar y) { if (x < y) x = y; }

inline Scalar min(Scalar x, Scalar y) { return x > y ? y : x; }
inline Scalar max(Scalar x, Scalar y) { return x < y ? y : x; }

const Scalar RADS_PER_DEG = M_PI / 180;

inline Scalar rads(Scalar x) { return x * RADS_PER_DEG; }
inline Scalar degs(Scalar x) { return x / RADS_PER_DEG; }

enum { X = 0, Y = 1, Z = 2, W = 3 };

#endif
